<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #outer{
            width: 800px;
            margin: 50px auto;
            padding: 10px;
            border: 10px double black;
            text-align: center;
        }

        
    </style>

    <script>
        window.onload = function(){
            var prev = document.getElementById("prev");
            var next = document.getElementById("next");


            var img = document.getElementsByTagName("img")[0];
            var imgArray = ["../img-1.jpg" ,"../img-2.jpg","../img-3.jpg","../img-4.jpg","../img-5.jpg","../img-6.jpg"];
            var index = 0;
            var info = document.getElementById("info");

            info.innerHTML = "一共"+imgArray.length+"张图片，当前是第"+(index+1)+"张。";
            prev.onclick = function(){
                index--;
                if(index < 0){
                    index = imgArray.length-1;
                }
                info.innerHTML = "一共"+imgArray.length+"张图片，当前是第"+(index+1)+"张。";
                img.src = imgArray[index];
                
            };
            next.onclick = function(){
                index++;
                if(index > imgArray.length-1){
                    index = 0;
                }
                info.innerHTML = "一共"+imgArray.length+"张图片，当前是第"+(index+1)+"张。";
                img.src = imgArray[index];
            };

        };
    </script>
</head>
<body>
    <div id="outer">

        <p id="info"></p>
        <img src="../img-1.jpg" alt="美女">

        <button id="prev">上一张</button>
        <button id="next">下一张</button>
    </div>

</body>

</html>